<?php
/**
 * SpecialARC2Admin is a Special page for setting up the database tables for an ARC2 RDF Store
 * @author samuel.lampa@gmail.com
 * @package SMWRDFConnector
 */
class SpecialARC2Admin extends SpecialPage {

    function __construct() {
        parent::__construct( 'SpecialARC2Admin' );
        wfLoadExtensionMessages('SpecialARC2Admin');
    }

    function execute( $par ) {
        global $wgRequest, $wgOut, $wgDBserver, $wgDBname, $wgDBuser, 
               $wgDBpassword, $smwgARC2StoreConfig, $wgArticlePath,
               $wgServer, $wgScriptPath;

        $this->setHeaders();
        $output = "";

        # Get request data from, e.g.
        $rdfio_action = $wgRequest->getText('rdfio_action');

        # instantiation
        $store = ARC2::getStore($smwgARC2StoreConfig);

        $output .= "\n===RDF Store Setup===\n'''Status:'''\n\n";

        if (!$store->isSetUp()) {
            $output .= "* Store is '''not''' set up\n";
            if ( $rdfio_action == "setup" ) {
                $output .= "* Setting up now ...\n";
                $store->setUp();
            }
        } else {
            $output .= "* Store is already set up.\n";
        }

        $wgOut->addWikiText( $output );

        $htmlOutput = '<form method="get" action="' . $wgServer . $wgScriptPath . '/index.php/Special:ARC2Admin"
            name="createEditQuery">
            <input type="submit" name="rdfio_action" value="setup">
            </form>';

        $wgOut->addHTML( $htmlOutput );

    }
}
